from flask import Blueprint
from flask import redirect
from flask import request
from flask import session

admin_blue = Blueprint("admin",__name__,url_prefix="/admin")

from . import views

# 使用请求钩子,拦截普通用户,before_request
# 只要是使用 admin 所修饰的函数都会拦截
@admin_blue.before_request
def before_request():
    # if request.url.endswith("/admin/login"):
    #     passe
    #     # 判断是否是管理员
    #     if session.get("is_admin"):
    #         pass
    #     else:
    #         return redirect("/")

    # 优化
    if not request.url.endswith("/admin/login"):
        if not session.get("is_admin"):
            return redirect("/")